<!DOCTYPE html>
<html lang="zh-CN"  xmlns:th="http://www.thymeleaf.org">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>课程过程化管理 </title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" th:href="@{/static/vendor/bootstrap/css/bootstrap.min.css}">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet" th:href="@{/static/vendor/font-awesome/css/font-awesome.min.css}">
    <!-- Fontastic Custom icon font-->
    <link rel="stylesheet" th:href="@{/static/css/fontastic.css}">
    <!-- Google fonts - Poppins -->
    <link rel="stylesheet" th:href="@{https://fonts.googleapis.com/css?family=Poppins:300,400,700}">
    <!-- theme stylesheet-->
    <link rel="stylesheet" th:href="@{/static/css/style.default.css}" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" th:href="@{/static/css/custom.css}">
    <!-- Favicon-->
    <link rel="shortcut icon" th:href="@{/static/img/favicon.ico}">
    <!-- Tweaks for older IEs--><!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->
  </head>
  <body>
    <div class="page">
      <!-- Main Navbar-->
      <header class="header">
        <nav class="navbar">
          <!-- Search Box-->
          <div class="search-box">
            <button class="dismiss"><i class="icon-close"></i></button>
            <form id="searchForm" action="#" role="search">
              <input type="search" placeholder="What are you looking for..." class="form-control">
            </form>
          </div>
          <div class="container-fluid">
            <div class="navbar-holder d-flex align-items-center justify-content-between">
              <!-- Navbar Header-->
              <div class="navbar-header">
                <!-- Navbar Brand --><a href="index.html" class="navbar-brand d-none d-sm-inline-block">
                  <div class="brand-text d-none d-lg-inline-block"><strong>侧栏</strong></div>
                  <div class="brand-text d-none d-sm-inline-block d-lg-none"><strong>BD</strong></div></a>
                <!-- Toggle Button--><a id="toggle-btn" href="#" class="menu-btn active"><span></span><span></span><span></span></a>
              </div>
              <!-- Navbar Menu -->
              <ul class="nav-menu list-unstyled d-flex flex-md-row align-items-md-center">
                <!-- Search-->
                <li class="nav-item d-flex align-items-center"><a id="search" href="#"><i class="icon-search"></i></a></li>
                <!-- Notifications-->
                <li class="nav-item dropdown"> <a id="notifications" rel="nofollow" data-target="#" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="nav-link"><i class="fa fa-bell-o"></i><span class="badge bg-red badge-corner">1</span></a>
                  <ul aria-labelledby="notifications" class="dropdown-menu">
                    <li><a rel="nofollow" href="#" class="dropdown-item"> 
                        <div class="notification">

                        </div></a></li>
                    <li><a rel="nofollow" href="#" class="dropdown-item all-notifications text-center"> <strong>view all notifications                                            </strong></a></li>
                  </ul>
                </li>
                <!-- Logout    -->
                <li class="nav-item"><a th:href="@{/logout}" class="nav-link logout"> <span class="d-none d-sm-inline">退出登录</span><i class="fa fa-sign-out"></i></a></li>
              </ul>
            </div>
          </div>
        </nav>
      </header>
      <div class="page-content d-flex align-items-stretch"> 
        <!-- Side Navbar -->
        <nav class="side-navbar">
          <!-- Sidebar Header-->
          <div class="sidebar-header d-flex align-items-center">

            <div class="avatar"><img th:src="@{/static/img/avatar-1.jpg}" alt="..." class="img-fluid rounded-circle"></div>
            <div class="title">
              <h1 class="h4" th:text="${session.Main.getId()}"></h1>
              <p>管理员编号:<p th:text="${session.loginUser}"></p></p>
            </div>
          </div>
          <!-- Sidebar Navidation Menus--><span class="heading">Main</span>
          <ul class="list-unstyled">
                    <li ><a th:href="@{/adminMain}"> </i>课程管理 </a></li>
                    <li><a th:href="@{/Admin/students}"></i>学生管理 </a></li>
                    <li class="active"><a th:href="@{/Admin/teachers}"></i>教师管理 </a></li>
                    <li><a th:href="@{/Admin/classname}"></i>班级管理 </a></li>
                    <li><a th:href="@{/}"> <i class="icon-interface-windows"></i>返回主页 </a></li>
          </ul>
        </nav>
        <div class="content-inner">
          <!-- Page Header-->
          <header class="page-header">
            <div class="container-fluid">
              <button type="button" class="btn btn-info"
                      data-toggle="modal" data-target="#addModal">添加教师</button>
              <button type="button" class="btn btn-danger" id="delCousers" onclick="delTeachers();">批量删除</button>
            </div>
          </header>
          <!-- Dashboard Header Section    -->
          <br>
          <div >
            <table id="table" class="table table-hover table-bordered" border="1"align="center">
              <thead><tr class="font">
                <td><input type="checkbox" name="items" onclick="checkAll(this)"> 全选</td>
                <td>老师编号</td><td>老师姓名</td><td>性别</td><td>操作</td></tr></thead>
              <tbody>
              <tr th:each="t,tState:${teachers}">
                <td><input type="checkbox" id="item" name="item" th:value="${t.getTid()}" /></td>
                <td th:text="${t.getTid()}"></td>
                <td th:text="${t.getTname()}"></td>

                <!-- 判断男女 -->
                <td th:if="${t.getTsex()==1}">男</td>
                <td th:if="${t.getTsex()==0}">女</td>
                
                <td>
                  <a th:href="@{/Admin/deleteT/{id}(id=${t.getTid()})}" class="btn btn-danger">删除</a>
                  <button type="button" class="btn btn-info" data-toggle="modal" data-target="#editModal"
                          onclick="editInfo(this)" th:id="${tState.index+1}">编辑</button>
                </td>
              </tr>
              </tbody>
            </table>
          </div>


          <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
              <div class="modal-content">

                <div class="modal-header">
                  <h4 class="modal-title" id="myModalLabel">
                    教师信息
                  </h4>
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    ×
                  </button>
                </div>
                <form th:action="@{/Admin/updateT}" method="post">
                  <div class="modal-body">
                    <div class="form-group">
                      <label for="teacherId" class="col-sm-3 control-label">老师ID</label>
                      <div class="col-sm-9">
                        <input type="text" class="form-control" id="teacherId" name="teacherId" readonly="true">
                      </div>
                    </div>

                    <div class="form-group">
                      <label for="tpswd" class="col-sm-3 control-label">教师密码</label>
                      <div class="col-sm-9">
                        <input type="password" class="form-control" id="tpswd" name="tpswd" placeholder="请输入密码">
                      </div>
                    </div>

                    <div class="form-group">
                      <label for="tname" class="col-sm-3 control-label">老师名字</label>
                      <div class="col-sm-9">
                        <input type="text" class="form-control" id="tname" name="tname" placeholder="请输入老师名字">
                      </div>
                    </div>

                    <div class="form-group">
                      <label for="man" class="col-sm-3 control-label">性别</label>
                      <div class="col-sm-9">
                        <input type="radio" name="tsex" class="sex" id="man" value="1" />&nbsp;男&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="tsex" class="sex" id="women" value="0" />&nbsp;女
                      </div>
                    </div>

                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <button type="submit" class="btn btn-primary">
                      提交
                    </button>
                  </div>
                </form>

              </div>

              <!-- /.modal-content -->

            </div>

            <!-- /.modal -->
          </div>



          <script language='javascript' th:inline="javascript">
              // 编辑课程
              function editInfo(obj) {
                  var id=$(obj).attr("id");
                  var tid=document.getElementById("table").rows[id].cells[1].innerText;
                  var tname = document.getElementById("table").rows[id].cells[2].innerText;
                  var tsex = document.getElementById("table").rows[id].cells[3].innerText;


                  $('#teacherId').val(tid);
                  $('#tname').val(tname);
                  if (tsex == '女') {
                      document.getElementById('women').checked = true;
                  } else {
                      document.getElementById('man').checked = true;
                  }

                  $.each([[${teachers}]][id-1],function(key,value){
                      if(key=="tpsw") {
                          var tpswd=value;
                          $('#tpswd').val(tpswd);
                      }
                  });

              }

              //全选课程
              function checkAll(c) {
                  var status = c.checked;
                  var oItems = document.getElementsByName('item');
                  for(var i=0;i<oItems.length;i++){
                      oItems[i].checked=status;
                  }
              }


              //删除所有选中
              function delTeachers() {
                  /*<![CDATA[*/
                  //判断至少写了一项
                  var checkedNum = $("input[name='item']:checked").length;
                  if(checkedNum==0){
                      alert("请至少选择一项!");
                      return false;
                  }
                  if(confirm("确定删除所选项目?")) {
                      var checkedList = new Array();
                      var delsUrl = /*[[@{/Admin/deleteTs}]]*/;//获取动作地址
                      $("input[name='item']:checked").each(function () {
                          checkedList.push($(this).val());
                      });
                      $.ajax({
                          type: "POST",
                          url: delsUrl,
                          data: {
                              "delitems": checkedList.toString()
                          },
                          datatype: 'json',
                          success: function (data) {
                              location.reload();//页面刷新
                          },
                          error: function (data) {
                              art.dialog.tips('删除失败!');
                          }
                      });
                  }
                  /*]]>*/
              }
          </script>


          <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel" aria-hidden="true">
            <div class="modal-dialog">
              <div class="modal-content">

                <div class="modal-header">
                  <h4 class="modal-title" id="addModalLabel">
                    教师信息
                  </h4>
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    ×
                  </button>
                </div>
                <form th:action="@{/Admin/addTeacher}" method="post">
                  <div class="modal-body">
                    <div class="form-group">
                      <label for="addtname" class="col-sm-3 control-label">教师名字</label>
                      <div class="col-sm-9">
                        <input type="text" class="form-control" id="addtname" name="addtname" placeholder="请输入教师名字">
                      </div>
                    </div>

                    <div class="form-group">
                      <label for="addtpswd" class="col-sm-3 control-label">教师密码</label>
                      <div class="col-sm-9">
                        <input type="password" class="form-control" id="addtpswd" name="addtpswd" placeholder="请输入密码(不填写默认为123456)">
                      </div>
                    </div>

                    <div class="form-group">
                      <label for="addman" class="col-sm-3 control-label">性别</label>
                      <div class="col-sm-9">
                        <input type="radio" name="addtsex" class="sex" id="addman" value="1" />&nbsp;男&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="addtsex" class="sex" id="addwomen" value="0" />&nbsp;女
                      </div>
                    </div>

                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <button type="submit" class="btn btn-primary">
                      提交
                    </button>
                  </div>
                </form>

              </div>

              <!-- /.modal-content -->

            </div>

            <!-- /.modal -->
          </div>



          <style type="text/css">

            tr.font {
              font-size: 20px;
            }
            table.imagetable {
              font-family: verdana,arial,sans-serif;
              font-size:11px;
              color:#333333;
              border-width: 1px;
              border-color: #999999;
              border-collapse: collapse;
            }
            table.imagetable th {
              background:#b5cfd2 url('css/bulecell.jpg');
              border-width: 1px;
              padding: 8px;
              border-style: solid;
              border-color: #999999;
            }
            table.imagetable td {
              background:#dcddc0 url('css/greycell.jpg');
              border-width: 1px;
              padding: 8px;
              border-style: solid;
              border-color: #999999;
            }
          </style>

          <!-- Page Footer-->
          <footer class="main-footer">
            <div class="container-fluid">
              <div class="row">
                <div class="col-sm-6">
                  <p>成都信息工程大学 &copy; 2019</p>
                </div>
              </div>
            </div>
          </footer>
        </div>
      </div>
    </div>
    <!-- JavaScript files-->
    <script th:src="@{/static/vendor/jquery/jquery.min.js}"></script>
    <script th:src="@{/static/vendor/popper.js/umd/popper.min.js}"> </script>
    <script th:src="@{/static/vendor/bootstrap/js/bootstrap.min.js}"></script>
    <script th:src="@{/static/vendor/jquery.cookie/jquery.cookie.js}"> </script>
    <script th:src="@{/static/vendor/chart.js/Chart.min.js}"></script>
    <script th:src="@{/static/vendor/jquery-validation/jquery.validate.min.js}"></script>
    <script th:src="@{/static/js/charts-home.js}"></script>
    <!-- Main File-->
    <script th:src="@{/static/js/front.js}"></script>
  </body>
</html>